<template>
  <el-row>
    <el-col :span="24">
      <el-tabs v-model="activeName">
        <el-tab-pane label="服务信息" name="1">
          <keep-alive>
            <service-info v-if="activeName == 1" :orderDetail="orderDetail" :id="id">
              <div slot="tools">
                <div><el-button type="primary" @click="additionalFees">追加费用</el-button></div>
                <div><el-button type="text" @click="refund(fhbOrder)">申请退款</el-button></div>
                <div><el-button type="text" @click="urge($event, fhbOrder)">一键催单</el-button></div>
                <div><el-button type="text" @click="feesDetail">费用详情</el-button></div>
              </div>
            </service-info>
          </keep-alive>
        </el-tab-pane>
        <el-tab-pane label="订单信息" name="2">
          <keep-alive>
            <order-info v-if="activeName == 2" :orderDetail="orderDetail" :id="id"></order-info>
          </keep-alive>
        </el-tab-pane>
        <el-tab-pane label="跟进记录" name="3">
          <keep-alive>
            <FollowUp v-if="activeName == 3" :id="id" :objectId="objectId" :objectType="objectType"></FollowUp>
          </keep-alive>
        </el-tab-pane>
        <el-tab-pane label="报价记录" name="4">
          <keep-alive>
            <quotation-record-info v-if="activeName == 4" :orderDetail="orderDetail"></quotation-record-info>
          </keep-alive>
        </el-tab-pane>
      </el-tabs>
    </el-col>
    <modalAdditionalFees :visible.sync="showModalAdditionalFees" :orderId="id"  @refresh="refresh"></modalAdditionalFees>
    <modalRefund :visible.sync="showModalRefund" :orderId="id" :refundIsOrNot="refundIsOrNot" @refresh="refresh"></modalRefund>
    <modal-fees-detail ref="modalFeesDetail" :orderId="id"></modal-fees-detail>
  </el-row>
</template>
<script>
import OrderInfo from '@/views/fhb/myOrders/components/info/OrderInfo'
import ServiceInfo from '@/views/fhb/myOrders/components/info/ServiceInfo'
import QuotationRecordInfo from '@/views/fhb/myOrders/components/info/QuotationRecordInfo'
import modalRefund from '@/views/fhb/myOrders/components/modal/modalRefund'
import modalAdditionalFees from '@/views/fhb/myOrders/components/modal/modalAdditionalFees'
import modalFeesDetail from '@/views/fhb/myOrders/components/modal/modalFeesDetail'
import {unixTimestampFilter, filterDataBaseDictionary, decimalNumFilter} from '@/filters'
import {dotData, confirm} from '@/utils'
import FollowUp from '@/views/fhb/business/FollowUp'
export default {
  name: 'myOrdersCompletedShow',
  components: {
    FollowUp,
    OrderInfo,
    ServiceInfo,
    QuotationRecordInfo,
    modalRefund,
    modalAdditionalFees,
    modalFeesDetail
  },
  filters: {
    decimalNumFilter,
    filterDataBaseDictionary,
    unixTimestampFilter
  },
  data() {
    return {
      id: this.$route.params.id,
      activeName: this.$route.query.tab ? String(this.$route.query.tab) : '1',
      objectId: this.$route.query.objectId ? String(this.$route.query.objectId) : '',
      objectType: this.$route.query.objectType ? String(this.$route.query.objectType) : '',
      orderDetail: {},
      autoEvaluationTime: 0,
      fhbOrderNodes: [],
      fhbOrder: {},
      fhbOrderBidding: {},
      fhbOrderGoods: [],
      fhbOrderConsigneeInfo: {},
      fhbOrderPickupInfo: {},
      fhbOrderBiddingLog: {},
      fhbOrderBiddingLogs: [],
      fhbOrderCollection: {},
      money: 0,
      goodsNum: 0,
      evalueForComplainTime: '',
      closeForComplainTime: '',
      isAbnormal: '',
      showModalAdditionalFees: false,
      showModalRefund: false,
      refundIsOrNot: '' // 退款订单是否关闭
    }
  },
  created() {
    this.getDetail()
  },
  methods: {
    getDetail() {
      this.$ajax.get('/ms-fahuobao-order/FhbOrder/findFhbOrderParticulars', {orderId: this.id}).then(response => {
        if (!response.data) {
          return
        }
        this.orderDetail = response.data
        this.autoEvaluationTime = this.orderDetail.autoEvaluationTime
        this.fhbOrderNodes = this.orderDetail.fhbOrderNodes || []
        this.fhbOrder = this.orderDetail.fhbOrder || {}
        this.fhbOrderBidding = this.orderDetail.fhbOrderBidding || {}
        this.fhbOrderGoods = this.orderDetail.fhbOrderGoods || []
        this.fhbOrderConsigneeInfo = this.orderDetail.fhbOrderConsigneeInfo || {}
        this.fhbOrderPickupInfo = this.orderDetail.fhbOrderPickupInfo || {}
        this.fhbOrderBiddingLog = this.orderDetail.fhbOrderBiddingLog || {}
        this.fhbOrderBiddingLogs = this.orderDetail.fhbOrderBiddingLogs || []
        // this.fhbOrderCollection = this.orderDetail.fhbOrderCollection || {}
        this.money = this.orderDetail.money
        for (let v of this.fhbOrderGoods) {
          this.goodsNum += (v.num ? parseInt(v.num) : 0)
        }
        this.evalueForComplainTime = this.orderDetail.evalueForComplainTime
        this.closeForComplainTime = this.orderDetail.closeForComplainTime
        this.isAbnormal = response.isAbnormal
      })
    },
    // 表格刷新
    refresh() {
      this.getDetail()
    },
    // 退款
    refund(item) {
      this.refundIsOrNot = item.orderIsCancel || ''
      this.showModalRefund = true
    },
    // 追加费用
    additionalFees(item) {
      // this.showModalAdditionalFees = true
      this.$router.push({path: '/ss-fhb/myOrders/confirming/paymentAdditional/' + this.fhbOrder.id, query: {bid: this.fhbOrderBiddingLog.id}})
    },
    // 费用详情
    feesDetail() {
      this.$refs.modalFeesDetail.show()
    },
    // 一键催单
    urge() {
      this.$ajax.get('ms-fahuobao-order/FhbOrder/stepReminder', {fhbOrderId: this.id}).then(response => {
        const success = dotData(response, 'success')
        if (success) {
          confirm('催单成功<br/>师傅已经接到你的催单提醒，将尽快为你服务', '温馨提示', {
            dangerouslyUseHTMLString: true,
            type: 'success',
            center: true,
            confirmButtonText: '确定',
            showCancelButton: false,
            closeOnClickModal: false
          })
        }
      })
    }
  }
}
</script>
